package com.axxc.cloud.service.impl;

import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.axxc.cloud.annotation.Owner;
import com.axxc.cloud.annotation.SystemOperationLog;
import com.axxc.cloud.enums.ExecuteMethodType;
import com.axxc.cloud.mapper.IScBaseConcernRecommendRecordMapper;
import com.axxc.cloud.model.ScBaseConcernRecommendRecord;
import com.axxc.cloud.service.api.IScBaseConcernRecommendRecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Builder;
import tk.mybatis.mapper.util.Sqls;

@Service
public class ScBaseConcernRecommendRecordServiceImpl implements IScBaseConcernRecommendRecordService {

	@Autowired
	private IScBaseConcernRecommendRecordMapper baseConcernRecommendRecordMapper;

	@Override
	public List<ScBaseConcernRecommendRecord> list() {
		return this.baseConcernRecommendRecordMapper.selectAll();
	}

	@Override
	public List<ScBaseConcernRecommendRecord> selectByExample() {
		// 同MGB的example
		Example example = new Example(ScBaseConcernRecommendRecord.class);
		example.createCriteria().andEqualTo("id", 19);
		this.baseConcernRecommendRecordMapper.selectByExample(example);

		// 基于构造模式的Sqls,也类似于example
		Builder builder = Example.builder(ScBaseConcernRecommendRecord.class);
		Sqls sqls = Sqls.custom().andGreaterThan("id", 0);
		Example example2 = builder.where(sqls).orderByDesc("id").build();
		PageHelper.startPage(2, 10);
		Page<ScBaseConcernRecommendRecord> example3 = (Page<ScBaseConcernRecommendRecord>) this.baseConcernRecommendRecordMapper
				.selectByExample(example2);

		return example3;
	}

	@Override
	public PageInfo<ScBaseConcernRecommendRecord> listPageByExample(Example example, Integer pageNum,
			Integer pageSize) {

		if (pageNum == null || pageSize == null) {
			PageHelper.startPage(0, 10);
		} else {
			PageHelper.startPage(pageNum, pageSize);
		}

		// Page<ScBaseConcernRecommendRecord> page =
		// this.baseConcernRecommendRecordMapper.selectByExample(example);
		// page.getResult().forEach(e -> System.out.println(e));

		List<ScBaseConcernRecommendRecord> list = this.baseConcernRecommendRecordMapper.selectByExample(example);

		return new PageInfo<>(list);
	}

	@Override
	public PageInfo<ScBaseConcernRecommendRecord> selectByExampleAndRowBounds(Example example, RowBounds rowBounds) {
		List<ScBaseConcernRecommendRecord> list = this.baseConcernRecommendRecordMapper
				.selectByExampleAndRowBounds(example, rowBounds);
		return new PageInfo<ScBaseConcernRecommendRecord>(list);
	}

	@Override
	@SystemOperationLog(dataBaseName = "test", tableName = "sc_base_concern_recommend_record", executeMethodType = ExecuteMethodType.UPDATE, ownerGroupName = "研发部2组", owners = {
			@Owner(ownerContactWay = "15163245181", ownerName = "xxc") })
	public int updateByPrimaryKeySelective(ScBaseConcernRecommendRecord record) {
		logger.info(JSONObject.toJSONString(record));
		return baseConcernRecommendRecordMapper.updateByPrimaryKeySelective(record);
	}
}
